package com.haorui.lygyd.authority.dto;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.haorui.base.system.enumerate.AccountType;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * 创建人: 陈刚
 * 日期: 2017/8/10
 * 时间: 0:23
 * 功能：账户授权
 */
public class AuthAccount implements UserDetails {

    @Getter
    @Setter
    private  String id;
    private  String username;
    @JSONField(serialize = false)
    private  String password;
    @Getter
    @Setter
    private  String email;
    private  Collection<? extends GrantedAuthority> authorities;
    @Getter
    @Setter
    private  Date lastPasswordResetDate;
    @Getter
    @Setter
    private String token;

    @Setter
    private boolean accountNonExpired=true;
    @Setter
    private boolean accountNonLocked=true;
    @Setter
    private boolean enabled=true;
    @Getter
    @Setter
    private AccountType accountType;
    @Getter
    @Setter
    private String photo;
    @Getter
    @Setter
    private String orgId;
    @Getter
    @Setter
    private String orgName;
    public AuthAccount(String id, String username, String password, String email, Collection<? extends GrantedAuthority> authorities, Date lastPasswordResetDate) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.email = email;
        this.authorities = authorities;
        this.lastPasswordResetDate = lastPasswordResetDate;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }
    // 账户是否未过期
    @Override
    public boolean isAccountNonExpired() {
        return accountNonExpired;
    }
    // 账户是否未锁定
    @Override
    public boolean isAccountNonLocked() {
        return accountNonLocked;
    }
    // 密码是否未过期
    @Override
    @JsonIgnore
    public boolean isCredentialsNonExpired() {
        return true;
    }
    // 账户是否激活
    @Override
    @JsonIgnore
    public boolean isEnabled() {
        return enabled;
    }
}
